home *** CD-ROM | disk | FTP | other *** search
- /* File: main.c
-
-
- The main program structure:
-
- int FixMenus()
- - Activate/Deactive menu as needed
-
- Edit Menu Stubs -- null routines...
-
- DoCommand(long mResult)
- - Handle all memu commands
-
- Boolean HandleEvents(EventRecord *myEvent);
-
- Initialize()
- - Setup up menus and Macintosh enviroment
-
- Main()
- - Setup QuickTime movie enviroment
- - Call Initialision routines
- - Call Main Event Handling routines
- - Cleanup QuickTime Movie Enviroment
-
- History..
- RMF Created from DTS from sample source code.
- */
-
- #include "gGlobals.h"
-
- #include <pascal.h>
- #include <Scrap.h>
- #include <Desk.h>
- #include <string.h>
- #include <stdio.h>
- #include <Fonts.h>
- #include <Math.h>
-
- /* *****************************************************************************
-
- The following three routines are here because the MPW 3.2 c compiler
- screw up compiling the DoMovie routine if you use the "straight" calls.
-
- Try it and see and complain to DTS.
- */
-
- void DoHLock(Handle h)
- {
- HLock(h);
- }
- void DoHUnlock(Handle h)
- {
- HUnlock( h);
- }
-
- void DoDisposHandle(Handle h)
- {
- DisposHandle(h);
- }
-
- /*********************************************
-
- Clean up menu hiliting
-
- *********************************************/
-
- int FixMenus()
- {
- Boolean gotAllWindows;
- Boolean gotAnyWindows = gSrcWindow != nil || gAltWindow != nil ;
-
- gotAllWindows = gSrcWindow != nil &&
- (!gRequiresAlternate || gAltWindow != nil );
- DisableItem(gMenus[FILE_MENU],FILE_M_SAVE);
- if ( gotAnyWindows )
- EnableItem(gMenus[FILE_MENU],FILE_M_CLOSE);
- else
- DisableItem(gMenus[FILE_MENU],FILE_M_CLOSE);
-
- if (gotAllWindows )
- DisableItem(gMenus[FILE_MENU],FILE_M_OPEN);
- else
- EnableItem(gMenus[FILE_MENU],FILE_M_OPEN);
-
- if ( !gotAllWindows ) {
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_APPEND);
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_MOVIE);
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_PREVIEW);
- DisableItem(gMenus[MOVIE_MENU],MOVIE_M_OVERSAMPLE);
- } else {
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_APPEND);
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_MOVIE);
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_PREVIEW);
- EnableItem(gMenus[MOVIE_MENU],MOVIE_M_OVERSAMPLE);
- }
-
- DisableItem(gMenus[EDIT_MENU],EDIT_M_CUT);
- DisableItem(gMenus[EDIT_MENU],EDIT_M_COPY);
- DisableItem(gMenus[EDIT_MENU],EDIT_M_PASTE);
-
- DisableItem(gMenus[EDIT_MENU],EDIT_M_CLEAR);
- DisableItem(gMenus[EDIT_MENU],EDIT_M_UNDO);
- CheckItem(gMenus[MOVIE_MENU],MOVIE_M_OVERSAMPLE,gOversample);
-
- CheckItem(gMenus[EFFECT_MENU],EFFECT_BACKWARDS,gBackwards);
- CheckItem(gMenus[EFFECT_MENU],EFFECT_Roll,gDoRollFill);
-
- CheckItem(gMenus[EFFECT_MENU],gDoCrossFade,true);
-
- }
-
-
- /*********************************************
-
- Stubs
-
- ********************************************/
-
- OSErr DoCopy()
- {
-
- }
-
- OSErr DoCut()
- {
- }
-
-
- OSErr DoPaste()
- {
-
- }
-
- void DoClear()
- {
-
-
- }
-
- OSErr DoUndo()
- {
-
-
- }
-
-
- /*********************************************
-
- Process menu command.
-
- ********************************************/
-
- DoCommand(long mResult)
- {
- short theMenu, theItem;
- Str255 daName;
- GDHandle saveGD;
- CGrafPtr savePort;
- OSErr res = 0;
-
- #define HIshort(aLong) (((aLong) >> 16) & 0xFFFF)
- #define LOshort(aLong) ((aLong) & 0xFFFF)
-
- theItem = LOshort(mResult);
- theMenu = HIshort(mResult); /* This is the resource ID */
-
-
- switch (theMenu) {
- case APPLE_MENU_ID:
- if (theItem == 1) {
- ShowAboutBox();
- } else {
- GetItem(gMenus[0], theItem, daName);
- GetGWorld(&savePort,&saveGD);
- (void) OpenDeskAcc(daName);
- SetGWorld(savePort,saveGD);
- }
- break;
-
- case FILE_MENU_ID:
- {
-
- switch (theItem) {
- case FILE_M_OPEN:
- DoOpen(nil);
- FixMenus();
- break;
- case FILE_M_CLOSE:
- DoClose(gActiveWindow);
- FixMenus();
- res = 1;
- break;
- case FILE_M_SAVE:
- FixMenus();
- break;
-
- case fileImport:
- importMovie();
- break;
-
- case fileExport:
- exportMovie();
- break;
-
-
- case FILE_M_QUIT:
- {
- Boolean abortion = false;
- while ( gActiveWindow ) {
- if ( DoClose(gActiveWindow) < 0 ) {
- abortion = true;
- break;
- }
- }
- if ( !abortion )
- gExitFlag = true; /* Request exit */
- res = 1;
- break;
- }
- }
- }
- break;
- case EDIT_MENU_ID:
- if ( !SystemEdit(theItem-1) ) {
- switch ( theItem ) {
- case EDIT_M_UNDO:
- DoUndo();
- break;
- case EDIT_M_CUT:
- DoCut();
- break;
- case EDIT_M_COPY:
- DoCopy();
- break;
- case EDIT_M_PASTE:
- DoPaste();
- break;
- case EDIT_M_CLEAR:
- DoClear();
- break;
- }
- }
- FixMenus();
- break;
-
- case EFFECT_MENU_ID:
- switch (theItem) {
- case EFFECT_BACKWARDS:
- DoClose((WindowPtr)gDstWindow);
- gBackwards = !gBackwards;
- break;
- case EFFECT_Roll:
- gDoRollFill = 1 - gDoRollFill;
- break;
- default:
-
- CheckItem(gMenus[EFFECT_MENU],gDoCrossFade,false);
- gDoCrossFade = theItem;
- CheckItem(gMenus[EFFECT_MENU],gDoCrossFade,true);
-
- gStandardP.flags = scShowMotionSettings;
- gStandardP.theCodecType = kCodecType;
- gStandardP.theCodec = kCodecID;
- gStandardP.spatialQuality = kCodecQuality;
- gStandardP.temporalQuality = 0;
- gStandardP.depth = kCodecDepth;
- gStandardP.frameRate = kFrameRate<<16;
- gStandardP.keyFrameRate = kFrameRate;
-
-
- if ( !gDoCrossFade != EFFECT_CrossFad ) {
- gDepth = 40; // randomdotstereogram needs grayscale buffers
- gStandardP.theCodecType = 'smc '; // graphics compressor is good choice
- gStandardP.depth = gDepth; // prime depth for std compression
- gRequiresAlternate = false; // only needs one pict to do processing
- } else {
- gStandardP.depth = 32; // full resolution for best effect
- gRequiresAlternate = true; // needs two picts to do processing
- }
- } /* End switch */
-
- FixMenus();
- break;
-
- case MOVIE_MENU_ID:
-
- switch ( theItem ) {
- case MOVIE_M_COMPRESS :
- SetCompression();
- break;
-
- case MOVIE_M_STAGES :
- DoClose((WindowPtr)gDstWindow);
- SetStages();
- break;
-
- case MOVIE_M_OVERSAMPLE:
- gOversample = !gOversample;
- CheckItem(gMenus[MOVIE_MENU],theItem,gOversample);
- break;
-
- case MOVIE_M_PREVIEW :
- DoPreview();
- break;
-
- case MOVIE_M_MOVIE :
- DoMovie(false);
- break;
- case MOVIE_M_APPEND :
- DoMovie(true);
- break;
-
- }
- break;
-
- default:
- break;
-
- }/*endsw theMenu*/
-
- HiliteMenu(0);
- return(res);
- } /* End of () */
-
-
- /********************************************
-
- Process events.
-
- ********************************************/
-
- Boolean HandleEvents(EventRecord *myEvent)
- {
- Rect dragRect;
- WindowPtr whichWindow;
- short res = 0;
- GWorldPtr saveWorld;
- GDHandle saveGD;
-
- GetGWorld(&saveWorld,&saveGD);
-
- switch (myEvent->what) {
- case mouseDown:
- switch ((short)FindWindow(myEvent->where, &whichWindow)) {
- case inSysWindow:
- SystemClick(myEvent, whichWindow);
- break;
-
- case inMenuBar:
- res = DoCommand(MenuSelect(myEvent->where));
- break;
-
- case inDrag:
- SetPort((GrafPtr)whichWindow);
- SetRect(&dragRect, 4, 20 + 4, qd.screenBits.bounds.right-4, qd.screenBits.bounds.bottom-4);
- DragWindow(whichWindow, myEvent->where, &dragRect);
- break;
-
- case inGrow:
- break;
-
- case inGoAway:
- if ( TrackGoAway(whichWindow,myEvent->where) ) {
- DoClose(whichWindow);
- FixMenus();
- res = true;
- }
- break;
-
- case inZoomIn:
- break;
-
- case inZoomOut:
- break;
-
- case inContent:
-
- if ( whichWindow != FrontWindow() ) {
- SelectWindow(whichWindow);
- gActiveWindow = whichWindow;
- }
- FixMenus();
- break;
-
- default:
- break;
- }
- break;
-
- case keyDown:
- if ( ((myEvent->modifiers & cmdKey) != 0) ) {
- res = DoCommand(MenuKey(myEvent->message & charCodeMask));
- }
- break;
-
- case updateEvt :
-
- DoUpdate((CWindowPtr)myEvent->message);
- break;
-
- case activateEvt:
- whichWindow=(WindowPtr)myEvent->message;
- if ( (myEvent->modifiers & activeFlag) ) {
- gActiveWindow = whichWindow;
- }
- break;
-
- default:
- break;
-
- }
- SetGWorld(saveWorld,saveGD);
- return(res);
- } /* End of () */
-
-
- /*********************************************
-
- Initialize menu bar.
-
- *********************************************/
-
- SetupMenus()
- {
- gMenus[APPLE_MENU] = GetMenu(APPLE_MENU_ID);
- AddResMenu(gMenus[APPLE_MENU], (ResType) 'DRVR');
- InsertMenu(gMenus[APPLE_MENU], 0);
- gMenus[FILE_MENU] = GetMenu(FILE_MENU_ID);
- InsertMenu(gMenus[FILE_MENU], 0);
- gMenus[EDIT_MENU] = GetMenu(EDIT_MENU_ID);
- InsertMenu(gMenus[EDIT_MENU], 0);
- gMenus[MOVIE_MENU] = GetMenu(MOVIE_MENU_ID);
- InsertMenu(gMenus[MOVIE_MENU], 0);
- gMenus[EFFECT_MENU] = GetMenu(EFFECT_MENU_ID);
- InsertMenu(gMenus[EFFECT_MENU], 0);
-
- DrawMenuBar();
- FixMenus();
- } /* End of () */
-
- /*********************************************
-
- Prepare for work.
-
- *********************************************/
-
- int Initialize()
- { OSErr err;
- Ptr size;
- long resp;
-
- size = GetApplLimit();
- SetApplLimit(size - 32*1024); /* make room on stack so Quickdraw can do big pictures */
- MaxApplZone();
-
- /* initialize managers */
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitDialogs(nil);
- InitCursor();
- FlushEvents(everyEvent, 0);
-
- SetupMenus(); /* Check off correct memus and hilight them */
-
- CouldAlert(140); /* Load Alert into Memory ... incase of out of memory errors */
-
-
- if ( NGetTrapAddress(0xab1d,ToolTrap) == NGetTrapAddress(0x9f,ToolTrap) ) {
- return -1;
- }
- if ( Gestalt(gestaltQuickTime, &resp) != 0 ) {
- return -1;
- }
-
- gHasNewStdFile = false; /* Check for preview and new standard file stuff */
- err = Gestalt(gestaltStandardFileAttr,&resp);
- if ((err == 0) && ((resp & (0x00000001 << gestaltStandardFile58)) != 0))
- gHasNewStdFile = true;
-
- InitSetCompression(); /* Setup default QT compression settings */
-
- return 0;
- } /* End of () */
-
-
- /*********************************************
-
- If some kind of fatal error happened come here.
-
- *********************************************/
-
- void Error(char *msg, OSErr code)
- { Str15 buf;
- GWorldPtr saveWorld;
- GDHandle saveGD;
- CGrafPtr wmgrPort;
- extern char *moviesErrorNames[];
-
- GetGWorld(&saveWorld,&saveGD); GetCWMgrPort(&wmgrPort);
- SetGWorld(wmgrPort,nil);
- if (code ) {
- NumToString(code, buf);
- } else buf[0] = 0;
-
- c2pstr(msg);
- if (code >= -2051 && code<= -2000) {
- c2pstr(moviesErrorNames[-code - 2000]);
- ParamText((StringPtr)msg,buf,(StringPtr) moviesErrorNames[-code - 2000],0);
- p2cstr((StringPtr)moviesErrorNames[-code - 2000]);
- } else
- ParamText((StringPtr)msg,buf,0,0);
- if ( code == 0 )
- Alert(140,nil);
- else
- StopAlert(140,nil);
- p2cstr((StringPtr) msg);
-
- SetGWorld(saveWorld,saveGD);
- } /* End of () */
-
-
- ShowAboutBox()
- {
-
- ParamText( "\pCreated from:\r\rPictMovier & ImportExportMovie QuickTime Sample Code",
- "\p",
- "\p\r\rChange By R.Mark Fleming <MarkF@post.QueensU.CA",0);
- Alert(140,nil);
- } /* End of () */
-
-
- /********************************************
-
- The main program
-
- - Setup QuickTime movie enviroment
- - Call Initialision routines
- - Call Main Event Handling routines
- - Cleanup QuickTime Movie Enviroment
-
- ********************************************/
-
- main()
- { EventRecord myEvent;
-
- if (Initialize()) {
- SysBeep(0); ExitToShell();
- }
-
- EnterMovies();
-
- if ( !gDoCrossFade ) {
- gDepth = 40; // randomdotstereogram needs grayscale buffers
- gStandardP.theCodecType = 'smc '; // graphics compressor is good choice
- gStandardP.depth = gDepth; // prime depth for std compression
- gRequiresAlternate = false; // only needs one pict to do processing
- } else {
- gStandardP.depth = 32; // full resolution for best effect
- gRequiresAlternate = true; // needs two picts to do processing
- }
-
- while ( !gExitFlag ) {
- if ( WaitNextEvent( everyEvent, &myEvent, 1, nil) != 0 ) {
- HandleEvents(&myEvent);
- }
- }
-
- done:
- ExitMovies();
- ExitToShell();
- } /* End of () */
-